package com.airconditioning.controller;

import com.airconditioning.service.IEnumService;
import com.airconditioning.entity.Enum;
import com.airconditioning.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
*
 * @author zhouyang
 * @since 2020-04-16
 */
@RestController
@RequestMapping("/enum")
public class EnumController {
    @Autowired
    public IEnumService enumService;

    /**
     * 保存、修改 【区分id即可】
     * @param enum  传递的实体
     * @return Ajaxresult转换结果
     */
    @RequestMapping(value="/save",method= RequestMethod.POST)
    public Result save(@RequestBody Enum enum){
        Result result = new Result();
        try {
            if(enum.getId()!=null){
                    enumService.updateByPrimaryKeySelective(enum);
            }else{
                    enumService.insertSelective(enum);
            }
            result.setData(true);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.setBizError("system error");
        }
    }

    //删除对象信息
    @RequestMapping(value="/{id}",method=RequestMethod.DELETE)
    public Result delete(@PathVariable("id") Long id){
        Result result = new Result();
        Enum enum = new Enum();
        enum.setIsDelete(true);
        try {
            enumService.updateByPrimaryKeySelective(enum);
            result.setData(true);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return  result.setBizError("id is error");
        }
    }

    //获取用户
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public Result get(@PathVariable("id")Long id)
    {
        Result result = new Result();
        try {
        result.setData(enumService.selectByPrimaryKey(id));
        return result;
        } catch (Exception e) {
            e.printStackTrace();
            return  result.setBizError("id is error");
        }
    }


}
